package cn.sdormitory.controller.exam;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.exam.entity.Exam;
import cn.sdormitory.exam.entity.ExamCourse;
import cn.sdormitory.exam.service.ExamService;
import cn.sdormitory.exam.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author : yy
 * @date: 2024/12/28 9:20
 * @description:
 */
@RestController
@Api(tags = "考试管理")
@RequestMapping("/exam")
public class ExamController {
    @Resource
    private ExamService examService;

    @ApiOperation("考试管理-分页查询")
    @GetMapping("/getList")
    public CommonResult<CommonPage<Exam>> getList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "examName", required = false) String examName
    ) {
        CommonPage<Exam> list = examService.getList(examName, pageNum, pageSize);
        return CommonResult.success(list);
    }
    @ApiOperation("考试管理-批量删除")
    @DeleteMapping(value = "/delExam/{ids}")
    public CommonResult delExam(@PathVariable Integer[] ids) {
        examService.delExam(ids);
        return CommonResult.success();
    }
    @ApiOperation("考试管理-发布或收回考试")
    @GetMapping("/updateExamRelease/{id}/{isRelease}")
    public CommonResult updateExamRelease(@PathVariable("id") Integer examId,
                                         @PathVariable("isRelease") Boolean isRelease) {
        examService.updateExamRelease(examId,isRelease);
        return CommonResult.success();
    }
    @ApiOperation(value = "考试管理-根据id获取考试信息")
    @GetMapping("/getExam/{id}")
    public CommonResult<EditExamVo> getEditExam(@PathVariable("id") Integer id) {
        return CommonResult.success(examService.getEditExam(id));
    }
    @ApiOperation(value = "考试管理-新增修改考试信息")
    @PostMapping("/editExam")
    public CommonResult editExam(@RequestBody EditExamVo editExamVo) {
        examService.editExam(editExamVo);
        return CommonResult.success();
    }
    @ApiOperation(value = "考试管理-获取考试班级信息")
    @GetMapping("/getExamClassList/{id}")
    public CommonResult<List<ExamClassVo>> getExamClassList(@PathVariable("id") Integer examId){
        List<ExamClassVo> list = examService.getExamClassList(examId);
        return CommonResult.success(list);
    }
    @ApiOperation(value = "考试管理-获取专业考试课程多选下拉列表")
    @GetMapping("/getCourseExamTypeOption")
    public CommonResult<List<Map<String,Object>>> getCourseExamTypeOption() {
        List<Map<String,Object>> list = examService.getCourseExamTypeOption();
        return CommonResult.success(list);
    }


    @ApiOperation(value = "考试成绩录入-根据课程类型获取该考试下的考试科目")
    @GetMapping("/getExamCourseTab")
    public CommonResult<List<ExamCourseTabVo>> getExamCourseTab(@RequestParam("examId") Integer examId,
                                                                @RequestParam("courseType") String courseType) {
        List<ExamCourseTabVo> list = examService.getExamCourseTab(examId,courseType);
        return CommonResult.success(list);
    }
    @ApiOperation(value = "考试成绩录入-修改考试课程信息")
    @PostMapping("editExamCourse")
    public CommonResult editExamCourse(@RequestBody List<ExamCourse> examCourses) {
        examService.editExamCourse(examCourses);
        return CommonResult.success();
    }
    @ApiOperation(value = "考试成绩录入-根据考试id,班级id,课程id获取成绩记录")
    @GetMapping("/getExamCourseScore")
    public CommonResult<List<ExamCourseScoreVo>> getExamCourseScore(@RequestParam("classId") Integer classId,
                                                                    @RequestParam("examId") Integer examId,
                                                                    @RequestParam("courseId") Integer courseId,
                                                                    @RequestParam(value = "studentName", required = false) String studentName,
                                                                    @RequestParam(value = "examType", required = false) String examType) {
        List<ExamCourseScoreVo> list = examService.getExamCourseScore(classId,examId,courseId,studentName,examType);
        return CommonResult.success(list);
    }
    @ApiOperation(value = "考试成绩录入-录入学生考试课程成绩")
    @PostMapping("enterExamCourseStudentScore")
    public CommonResult enterExamCourseStudentScore(@RequestBody List<ExamCourseScoreVo> examCourseScoreVos) {
        examService.enterExamCourseStudentScore(examCourseScoreVos);
        return CommonResult.success();
    }
    @ApiOperation(value = "考试成绩录入-根据考试id,班级id获取学生总成绩记录")
    @GetMapping("/getExamTotalScore")
    public CommonResult<List<ExamTotalScoreVo>> getExamTotalScore(@RequestParam("classId") Integer classId,
                                                                  @RequestParam("examId") Integer examId,
                                                                  @RequestParam(value = "studentName", required = false) String studentName) {
        List<ExamTotalScoreVo> list = examService.getExamTotalScore(classId,examId,studentName);
        return CommonResult.success(list);
    }





}
